<div class="wrapper clearfix">
    
    <!-- 右边内容开始 -->
    
    <div class="contenter f-r">
    
        	
        	<?php if(!$searchBooks):?>
        	<div class="alert alert-nobook">
        		没有搜到和&nbsp;“<b style="color:#F00;"><?php echo $this->input->get('r');?></b>”&nbsp;有关的教材！！！<br />输入名称关键短词（比如：计算机）、作者、ISBN号试试
        		
        	</div>
        	<?php endif;?>
        	
        	<!--<div class="list clearfix">-->
                <?php foreach ($searchBooks as $booksVal): ?>

                <div class="item">
                
                	<li class="image">
                		<a href="<?php echo base_url("lists/item/".$booksVal->book_id); ?>" target="_blank">
                			<img src="<?php echo base_url("uploads/thumb_220/".$booksVal->book_img); ?>" width="120" />
                		</a>
                	</li>
                	
                	<div class="rightname">
	                    <h3><a href="<?php echo base_url(); ?>lists/item/<?php echo $booksVal->book_id; ?>" target="_blank"><?php echo $booksVal->book_name; ?></a></h3>
	                    <li class="price clearfix"><span class="f-l"><em>￥</em><?php echo $booksVal->book_price; ?></span><span class="f-r">￥<?php echo $booksVal->book_pricing; ?></span></li>
	                    <?php if($booksVal->book_store < 1): ?>
	                    <li class="notic"><span class="label label-danger">暂时缺货</span></li> 
						<?php endif; ?>
	                </div>

                </div><!-- item -->
            	<?php endforeach; ?>
             
            <!--</div>--><!-- list -->

        <div class="pagination"><?php echo $this->pagination->pagination('3'); ?></div>

    </div><!-- contenter -->

</div><!-- wrapper -->

<script src="<?php echo base_url('static/javascript/collect.js');?>"></script>
<script>

// decrease , button click
$(".shopcar").children('.l').click(function(){
    $($(this).parent().children('.form-control')).popover('destroy');
    $(this).parent().removeClass('has-error');

    // decrease button click
    if(parseInt($(this).parent().children('.form-control').val()) <= 1)
    {
        // when input val < 1 ,show error
        $(this).parent().children('.form-control').parent().addClass('has-error');
        $(this).parent().children('.form-control').attr('data-content','本商品一件起卖');
        $(this).parent().children('.form-control').attr('data-placement','top');
        $(this).parent().children('.form-control').popover('show');
        $(this).parent().children('.form-control').val('1'); //set input val = 1
    }
    else
    {
        $(this).parent().children('.form-control').val(parseInt($(this).parent().children('.form-control').val()) - 1);
    }

});

// increase, click button
$(".shopcar").children('.r').click(function(){

    // clear error
    $($(this).parent().children('.form-control')).popover('destroy');
    $(this).parent().removeClass('has-error');

    $(this).parent().children('.form-control').val(parseInt($(this).parent().children('.form-control').val()) + 1);

});

//clear error
$("input").focus(function(){
        
    $(this).popover('destroy');
    $(this).parent().removeClass('has-error');
});

//当用户输入的商品数量小于1,则提示用户，并强行设置数量为1
$(".shopcar").children('.form-control').change(function(){
    if( (parseInt($(this).val()) <= 1) || ($(this).val() ==''))
    {
        // when input val < 1 ,show error
        $(this).parent().addClass('has-error');
        $(this).attr('data-content','本商品一件起卖');
        $(this).attr('data-placement','top');
        $(this).popover('show');
        $(this).val('1'); //set input val = 1
    }

});


// 将物品加入购物车
$(".addshopcar").click(function(){

    //clear error
    $($(this).parent().children('.form-control')).popover('destroy');
    $(this).parent().removeClass('has-error');

    var qty = $(this).prevAll('.form-control').val(); // 用户购买的物品数量
    var id = $(this).attr('data-bookid'); // 用户购买物品的ID
    var bookname = $(this).parent().parent().siblings("h3").children('a').html(); //商品的名称
    var price = $(this).parent().parent().siblings(".price").children('span').html(); //商品的价格
    var book_img = $(this).parent().parent().siblings(".image").children('a').children('img').attr('src'); //商品的图片
    
    $("#shopcarModal .book-info h3 a").html(bookname); 
    $("#shopcarModal .book-info li").html(price); 
    $("#shopcarModal .book-info img").attr("src",book_img); 
    
    var this_form = $(this).siblings('.form-control');
    
    $.ajax({
    	
        url:"<?php echo base_url('shopcar/addShopCarAjax');?>",
        dataType:'json',
        type:'post',
        data:{"qty":qty,"id":id},
        success:function(e){
            if(e.store_warn){
                this_form.parent().addClass('has-error');
                this_form.attr('data-content','库存不足！%>_<%');
                this_form.attr('data-placement','top');
                this_form.popover('show');
            }else{
            	$("#shopcarModal").modal("show");
            	$("#showcontent").html(e);
            	
            	$("#shopcarAmount").html(e.amount);
            	$("#shopcarPirce").html("￥ "+e.price);

            	//改变头部购物车商品数量
            	$("#topShopcar em").html(e.amount);

            }  

            
        }

	});

   

});


//当页面滚动时候切换导航栏效果
/* $(window).scroll(function(){
    if($(window).scrollTop() > 120 ){
        $(".classbar").css({"position":"fixed","top":"0","left":"0"});
        $("#firstclass").hide();
        $("#firstsearch").show();
    }else{
        $(".classbar").css({"position":"static"});
        $("#firstclass").show();
        $("#firstsearch").hide();
    }
}); */



</script>

<script src="<?php echo base_url('static/javascript/lists/collect.js');?>"></script>

<?php $this->load->view("lists/shopcarModal");?>
